# Multi-Threading Basic Linear Algebra Subprograms (MTBLAS)
#
# Building by using PMake
#
# $ MTBLAS: Makefile    Rev. 0.0.10    2013-10-21T10:41+08:00 $

.include <../../Makefile.mk>

CFLAGS= -O2 -Wall -Winline -std=c99

## DO NOT COMMENT OUT THE FOLLOW BELOW LINE ##
CFLAGS+= ${CONFIGURE_ARGS}
## DO NOT COMMENT OUT THE FOLLOW ABOVE LINE ##


STATIC_OBJS= libstblas.a libmtblas.a
SHARED_OBJS= libstblas.so libmtblas.so

BUILD_OBJS= ${STATIC_OBJS}

.ifndef WITHOUT_SHARED
BUILD_OBJS+= ${SHARED_OBJS}
.endif

build: ${BUILD_OBJS}


# ISA Kernel
ISA_OBJS= exec_isa.o isa_op2.o isa_op3.o isa_op4.o
exec_isa.o: exec_isa.c
	${STDCC} -fpic -c exec_isa.c ${CFLAGS} -I./

exec_pthd.o: exec_pthd.c
	${STDCC} -fpic -c exec_pthd.c ${CFLAGS} -I./ -I../base/

isa_op2.o: isa_op2.c
	${STDCC} -fpic -c isa_op2.c ${CFLAGS} -I./

isa_op3.o: isa_op3.c
	${STDCC} -fpic -c isa_op3.c ${CFLAGS} -I./

isa_op4.o: isa_op4.c
	${STDCC} -fpic -c isa_op4.c ${CFLAGS} -I./


# Common Operating Rutine
COR_OBJS= cor_ctrl.o
cor_ctrl.o: cor_ctrl.c
	${STDCC} -fpic -c cor_ctrl.c ${CFLAGS} -I./ -I../base/


# Single-Thread Basic Linear Algebra Subprograms
ST1_OBJS= stblas_1_dot.o stblas_1_nrm.o stblas_1_scp.o stblas_1_scl.o
#ST1_OBJS= stblas_1_dot.o stblas_1_nrm.o stblas_1_scp.o stblas_1_rot.o stblas_1_scl.o
ST2_OBJS= stblas_2_gmv.o
ST3_OBJS= stblas_3_gmm.o


libstblas.a: ${ISA_OBJS} ${COR_OBJS} ${ST1_OBJS} ${ST2_OBJS} ${ST3_OBJS}
	${AR} libstblas.a ${ISA_OBJS} ${COR_OBJS} ${ST1_OBJS} ${ST2_OBJS} \
	${ST3_OBJS}

libstblas.so: ${ISA_OBJS} ${COR_OBJS} ${ST1_OBJS} ${ST2_OBJS} ${ST3_OBJS}
	${LD} -shared -soname libstblas.so -o libstblas.so.0 ${ISA_OBJS} \
	${COR_OBJS} ${ST1_OBJS} ${ST2_OBJS} ${ST3_OBJS}
	${LN} ./libstblas.so.0 ./libstblas.so

# Level 1
stblas_1_dot.o: stblas_1_dot.c
	${STDCC} -fpic -c stblas_1_dot.c ${CFLAGS} -I./ -I../base/

stblas_1_nrm.o: stblas_1_nrm.c
	${STDCC} -fpic -c stblas_1_nrm.c ${CFLAGS} -I./ -I../base/

stblas_1_scp.o: stblas_1_scp.c
	${STDCC} -fpic -c stblas_1_scp.c ${CFLAGS} -I./ -I../base/

stblas_1_rot.o: stblas_1_rot.c
	${STDCC} -fpic -c stblas_1_rot.c ${CFLAGS} -I./ -I../base/

stblas_1_scl.o: stblas_1_scl.c
	${STDCC} -fpic -c stblas_1_scl.c ${CFLAGS} -I./ -I../base/

# Level 2
stblas_2_gmv.o: stblas_2_gmv.c
	${STDCC} -fpic -c stblas_2_gmv.c ${CFLAGS} -I./ -I../base/

# Level 3
stblas_3_gmm.o: stblas_3_gmm.c
	${STDCC} -fpic -c stblas_3_gmm.c ${CFLAGS} -I./ -I../base/


# Multi-Threading Basic Linear Algebra Subprograms
MT1_OBJS= mtblas_1_dot.o mtblas_1_nrm.o mtblas_1_scp.o mtblas_1_scl.o
MT2_OBJS= mtblas_2_gmv.o

libmtblas.a: ${ISA_OBJS} ${COR_OBJS} exec_pthd.o ${MT1_OBJS} ${MT2_OBJS}
	${AR} libmtblas.a ${ISA_OBJS} ${COR_OBJS} exec_pthd.o ${MT1_OBJS} \
	${MT2_OBJS}

libmtblas.so: ${ISA_OBJS} exec_pthd.o ${MT1_OBJS} ${MT2_OBJS}
	${LD} -shared -soname libmtblas.so -o libmtblas.so.0 ${ISA_OBJS} \
	${COR_OBJS} exec_pthd.o ${MT1_OBJS} ${MT2_OBJS}
	${LN} ./libmtblas.so.0 ./libmtblas.so

# Level 1
mtblas_1_dot.o: mtblas_1_dot.c
	${STDCC} -fpic -c mtblas_1_dot.c ${CFLAGS} -I./ -I../base/

mtblas_1_nrm.o: mtblas_1_nrm.c
	${STDCC} -fpic -c mtblas_1_nrm.c ${CFLAGS} -I./ -I../base/

mtblas_1_scp.o: mtblas_1_scp.c
	${STDCC} -fpic -c mtblas_1_scp.c ${CFLAGS} -I./ -I../base/

mtblas_1_scl.o: mtblas_1_scl.c
	${STDCC} -fpic -c mtblas_1_scl.c ${CFLAGS} -I./ -I../base/

# Level 2
mtblas_2_gmv.o: mtblas_2_gmv.c
	${STDCC} -fpic -c mtblas_2_gmv.c ${CFLAGS} -I./ -I../base/

# Level 3


# Clean All Object Files
clean:
	${RM} *.o
	${RM} *.a
	${RM} *.so
	${RM} *.so.0
